/**
 * @file font_param.h
 * @author ThomasKingFree (dulu150@126.com)
 * @brief
 * @version 0.1
 * @date 2021-07-17
 *
 * @copyright Copyright (c) 2021
 *
 */

#ifndef FONT_PARAM_H
#define FONT_PARAM_H

#include "json.hpp"
#include "utils/gui_error.h"
#include <map>
#include <string>

namespace YueGUI {
enum OutputFormat {
    FILE,
    CARRAY,
};

struct UnicodeRange {
    uint32_t min = 0;
    uint32_t max = 0;
};

struct FontKey {
    std::string fontName;
    uint32_t fontSize;

    bool operator<(const FontKey &right) const;
};

const std::string JSON_LIST = "list";
const std::string JSON_FONT_NAME = "fontname";
const std::string JSON_FONT_SIZE = "fontsize";
const std::string JSON_GLYPH_RANGE = "range";
const std::string JSON_RANGE_MIN = "min";
const std::string JSON_RANGE_MAX = "max";

class FontConfig {
public:
    FontConfig();
    ~FontConfig();

    void SetOutputFormat(OutputFormat format);

    OutputFormat GetOutputFormat() const;

    int32_t LoadFontConfigFile(const std::string &path);

private:
    int32_t ConvertToGlyphRangeMap(const nlohmann::json &jsonConfig);

    int32_t ConvertFontConfig(const nlohmann::json &fontConfig);

    OutputFormat format_ = OutputFormat::FILE;
    std::map<FontKey, std::vector<UnicodeRange>> glyphRangeMap_;
};
} // namespace YueGUI
#endif
